package com.erp.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author lyb
 * 创建字符集过滤器
 */
@WebFilter("*.action")
public class CharsetFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //设置请求字符集
        servletRequest.setCharacterEncoding("utf-8");
        //设置响应字符集
        servletResponse.setCharacterEncoding("utf-8");
        //返回原页面
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
